#!/bin/bash

docker rm -f mysql_v3 &> /dev/null


------single----
docker run -ti --name=mysql_v3 \
-v $PWD/mysql_data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-p 3306:3306 mysql_v3 --character-set-server=utf8mb4 


--------master---------
docker run -ti --name=mysql_v3 \
-e ab_type=master \
-e ab_master_ip=198.199.108.10 \
-e MYSQL_ROOT_PASSWORD=123456 \
-p 3306:3306 \
mysql_v3 --character-set-server=utf8mb4 


--------slave--------
docker run -ti --name=mysql_v3 \
-e ab_type=slave \
-e ab_master_ip=198.199.108.10 \
-e MYSQL_ROOT_PASSWORD=123456 \
-p 3306:3306 \
mysql_v3 --character-set-server=utf8mb4 


docker exec -ti mysql_v3 bash

mkdir mysql_data
sudo rm -rf mysql_data

docker rmi -f mysql_v3 &> /dev/null
docker build -t mysql_v3 .


create database foobar;
use foobar;
create table blabla (id int PRIMARY KEY auto_increment, name varchar(10));
insert into blabla (name) values ("foo"),("bar");
select * from blabla;



### 获得镜像

#### 生成镜像
```
docker build -t mysql_v3 .
```

#### 导出镜像 (tar文件保存到u盘等)
```
docker save -o mysql_v3.tar mysql_v3
```

#### 导入镜像 (tar文件)
```
docker load -i mysql_v3.tar
```


mysql -uroot -pmysql -hlocalhost -e 'create database foobarblabla;'
mysql -uroot -pmysql -hlocalhost -e 'show databases; drop database if exists foobarblabla;'


mysql -uroot -p123456 -h104.236.154.96 -e 'show master status\G'
mysql -uroot -p123456 -h198.199.108.10 -e 'show master status\G'
mysql -uroot -p123456 -h159.203.221.126 -e 'show master status\G'

mysql -uroot -p123456 -e 'show slave status\g'

show variables like '%time%';
show variables like '%char%';
show variables like '%packet%';

docker exec mysql_v3 sh -c "mysql -uroot -p123456 -e 'show variables like \"%packet%\"'"

docker exec zookeeper sh -c "zkServer.sh status"

104.236.154.96,198.199.108.10,159.203.221.126